﻿using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
using NUnit.Framework;
using Rhino.Mocks;
using ShuttleBus.Transports.AmazonSqs.Clients;


namespace Tests.Transports.AmazonSqs.SnsWrapperTests
{
    public partial class SnsWrapperTests
    {
        [TestFixture]
        public class WhenSubscribing
        {
            private AmazonSimpleNotificationService _sns;
            private SnsWrapper _wrapper;

            [SetUp]
            public void SetUp()
            {
                _sns = MockRepository.GenerateMock<AmazonSimpleNotificationService>();
                _wrapper = new SnsWrapper(_sns);
            }

            [TearDown]
            public void TearDown()
            {
                _sns.VerifyAllExpectations();
            }

            [Test]
            public void Single_Topic()
            {
                var response = new SubscribeResponse();
                var topicArn = "topicArn";
                var queueArn = "queueArn";

                _sns.Expect(s => s.Subscribe(Arg<SubscribeRequest>.Matches(m => m.Endpoint == queueArn && m.TopicArn == topicArn && m.Protocol == "SQS"))).Return(response);

                _wrapper.Subscribe(queueArn, new[]{new Topic{TopicArn = topicArn} });
            }

            [Test]
            public void Multiple_Topics()
            {
                var queueArn = "queueArn";

                var response1 = new SubscribeResponse();
                var topicArn1 = "topicArn 1";

                var response2 = new SubscribeResponse();
                var topicArn2 = "topicArn 2";

                _sns.Expect(s => s.Subscribe(Arg<SubscribeRequest>.Matches(m => m.Endpoint == queueArn && m.TopicArn == topicArn1 && m.Protocol == "SQS"))).Return(response1);
                _sns.Expect(s => s.Subscribe(Arg<SubscribeRequest>.Matches(m => m.Endpoint == queueArn && m.TopicArn == topicArn2 && m.Protocol == "SQS"))).Return(response2);

                _wrapper.Subscribe(queueArn, new[] { new Topic { TopicArn = topicArn1 }, new Topic{TopicArn = topicArn2},  });
            }

        }
    }
}